package com.zenith.yasoo.security;


import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.annotation.Transactional;

import com.zui.base.BaseEntity;
import com.zui.base.EntityManagerImpl;

/**
 * 负责整个User模块内的业务.
 * 
 * 用@Transactional注明类里的每个方法都用事务的,对只读方法注明readOnly=true加强性能.
 * 
 * @author zhaoyong
 */
@Transactional
public class UserManagerImpl extends EntityManagerImpl<User, Long> implements
		UserManager {

	@Transactional(readOnly = true)
	public User getUser(Long id) {
		return super.getEntityDao().findById(id);
	}
	@Transactional(readOnly = true)
	public User getUserByLoginName(String userName) {
		DetachedCriteria dc = DetachedCriteria.forClass(User.class);
		dc.add(Restrictions.eq("userName", userName));
		dc.add(Restrictions.eq("isDeleted", BaseEntity.IS_DELETED_N));
		List<User> list = super.getEntityDao().findByCriteria(dc);
		if (list != null && !list.isEmpty())
			return list.get(0);
		else
			return null;
	}
}
